package com.lagou.rpc.consumer.loadbalancer;

import com.lagou.rpc.consumer.client.RpcClient;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
 * @Authther: mrwu
 * @date:2021/4/6-04
 * @Description:com.lagou.rpc.consumer.loadbalancer
 */
public class RpcBalancer {
    private List<RpcClient> balancer = new ArrayList<>();
    private int point=0;//当前坐标

    public RpcBalancer() {
        balancer.add(new RpcClient("127.0.0.1", 8899));
        balancer.add(new RpcClient("127.0.0.1", 8900));
    }

    //轮询获取rpcclient
    public RpcClient next(){
        point++;
        if (point==balancer.size()){
            point=0;
        }
        return balancer.get(point);
    }
}